//
//                            _ooOoo_
//                           o8888888o
//                           88" . "88
//                           (| -_- |)
//                           O\  =  /O
//                        ____/`---'\____
//                      .'  \\|     |//  `.
//                     /  \\|||  :  |||//  \
//                    /  _||||| -:- |||||-  \
//                    |   | \\\  -  /// |   |
//                    | \_|  ''\---/''  |   |
//                    \  .-\__  `-`  ___/-. /
//                  ___`. .'  /--.--\  `. . __
//               ."" '<  `.___\_<|>_/___.'  >'"".
//              | | :  `- \`.;`\ _ /`;.`/ - ` : | |
//              \  \ `-.   \_ __\ /__ _/   .-` /  /
//         ======`-.____`-.___\_____/___.-`____.-'======
//                            `=---='
//        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//                      佛祖保佑       永无BUG

import Vue from 'vue'

import axios from 'axios'

import VueCookie from 'vue-cookie'

import moment from 'vue-moment'

import router from './router'

import store from './store'

import Loading from './libs/loading.js'

import App from './App'

import config from './config'

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-default/index.css'

Vue.use(ElementUI)

window.store = store



let instance = axios.create({
  withCredentials: true
})

instance.interceptors.request.use(function(requestConfig){
  Vue.loading.show()
  requestConfig.crossOrigin = true
  return requestConfig;
},function(error){
  return Promise.reject(error);
})

instance.interceptors.response.use(function(response){
  Vue.loading.hide()
  response.body = response.data
  return response;
},function(error){
  Vue.loading.hide()
  let state = error.response.status + '';
  if (state === '494' || state.substr(0,2) === '50') {
    //window.location.href = 'http://www.sharingschool.net/'+config.sysConfig.SYSTEM_MAP.System+'/Maintain?status=' + state;
  }
  return Promise.reject(error);
})

Vue.prototype.$http = instance
Vue.http = instance


/**
 * plugins
 */
Vue.use(VueCookie)
Vue.use(moment)
Vue.use(Loading)

router.beforeEach((to, from, next) => {
    document.title = !!to.meta.title ? to.meta.title : ''
    window.document.body.style.overflow = 'scroll'
    window.document.body.style.position = 'initial'
    router.isShowNavbar = to.meta.isShowNavbar
    next()
})

let vm = new Vue({
    store,
    router,
    template: '<App/>',
    components: { App }
}).$mount('#app')
